//
//  KTNavTitleView.m
//  RuiHeApp
//
//  Created by Yan Chen on 2024/3/19.
//

#import "RHNavTitleView.h"
@interface RHNavTitleView()
@property (nonatomic ,strong) UIImageView *arrowImg;

@property (nonatomic ,strong) UIView *pointView;
@end
@implementation RHNavTitleView
-(instancetype)init{
    if(self = [super init]){
        [self setupUI];
    }
    return self;
}

-(void)setStatus:(NSString *)status
{
    _status = status;
    _devIdLab.textColor = FontColor(@"#666666");
    if([self.status isEqualToString:@"0"]){
        _pointView.backgroundColor = CMainColorGreen;
        _devIdLab.textColor = CMainColorGreen;
    }else if ([self.status isEqualToString:@"1"]){
        _pointView.backgroundColor = kCOLOR_HEX(@"BBBBBB");
    }else if ([self.status isEqualToString:@"2"]){
        _pointView.backgroundColor = kCOLOR_HEX(@"FA6334");
    }else{
        _pointView.backgroundColor = UIColor.clearColor;
    }
}

-(void)setupUI{
    kWeakSelf;
    _arrowImg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"nav_arrow_down"]];
    [self addSubview:_arrowImg];
    [_arrowImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.right.mas_offset(0);
        make.centerY.mas_offset(0);
    }];
    
    _devNameLab = [[QMUILabel alloc]init];
    _devNameLab.textColor = FontColor(@"#333333");
    _devNameLab.textAlignment = NSTextAlignmentCenter;
    _devNameLab.font = kBOLDSYSTEMFONT(16);
    [self addSubview:_devNameLab];
    [_devNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_offset(0);
        make.right.equalTo(weakSelf.arrowImg.mas_left).offset(-5);
    }];
    
    _pointView = kView;
    _pointView.layer.cornerRadius = 3;
    _pointView.layer.masksToBounds = YES;
    [self addSubview:_pointView];
    if([self.status isEqualToString:@"0"]){
        _pointView.backgroundColor = CMainColorGreen;
    }else if ([self.status isEqualToString:@"1"]){
        _pointView.backgroundColor = kCOLOR_HEX(@"BBBBBB");
    }else if ([self.status isEqualToString:@"2"]){
        _pointView.backgroundColor = kCOLOR_HEX(@"FA6334");
    }else{
        _pointView.backgroundColor = UIColor.clearColor;
    }
    

    
    _devIdLab = [[QMUILabel alloc]init];
    _devIdLab.textColor = FontColor(@"#666666");
    _devIdLab.textAlignment = NSTextAlignmentCenter;
    _devIdLab.font = kBOLDSYSTEMFONT(14);
    [self addSubview:_devIdLab];
    [_devIdLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.pointView.mas_right).offset(3);
        make.top.equalTo(weakSelf.devNameLab.mas_bottom);
        make.right.equalTo(weakSelf.arrowImg.mas_left).offset(-5);
        make.bottom.mas_offset(0);
    }];
    
    [_pointView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(6, 6));
        make.left.mas_offset(3);
        make.centerY.equalTo(weakSelf.devIdLab);
    }];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]init];
    [self addGestureRecognizer:tap];
    [tap.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
        if(weakSelf.tapAction){
            weakSelf.tapAction();
        }
    }];
}


-(void)hideArrowImg
{
    self.arrowImg.hidden = YES;
    [self.arrowImg mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(0);
    }];
    
}


@end
